package com.aiyige.model.request;

import com.aiyige.base.api.ApiManager;
import com.aiyige.page.publish.util.PublishUtil;

import java.util.LinkedList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;

/**
 * Created by zhuyakun on 2017/11/16.
 */

public class PublishCourseVideoRequest {
    private Long goodsId;
    private Integer version;
    private String operType;
    private int type;
    private String title;
    private String detail;
    private String cover = null;
    private String city;
    private int amount;
    private double lng;
    private double lat;
    private List<Long> tagIds = null;
    private long interest;
    private List<Guarantee> guarantees = null;
    private List<Video> videos = null;

    private PublishCourseVideoRequest(Builder builder) {
        setGoodsId(builder.goodsId);
        setVersion(builder.version);
        setOperType(builder.operType);
        setType(builder.type);
        setTitle(builder.title);
        setDetail(builder.detail);
        setCover(builder.cover);
        setCity(builder.city);
        setAmount(builder.amount);
        setLng(builder.lng);
        setLat(builder.lat);
        setTagIds(builder.tagIds);
        setInterest(builder.interest);
        setGuarantees(builder.guarantees);
        setVideos(builder.videos);
    }

    public static Builder newBuilder() {
        return new Builder();
    }


    public static class Guarantee {
        private Integer id;
        private long configId;
        private boolean isSupply;

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public long getConfigId() {
            return configId;
        }

        public void setConfigId(long configId) {
            this.configId = configId;
        }

        public boolean isSupply() {
            return isSupply;
        }

        public void setSupply(boolean supply) {
            isSupply = supply;
        }
    }

    public static class Video {
        private Integer id;
        private int type;
        private List<String> covers = null;
        private String title;
        private boolean isFree;
        private long duration;
        private long size;
        private String url;
        private int status;
        private int qiniuStatus;

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public List<String> getCovers() {
            return covers;
        }

        public void setCovers(List<String> covers) {
            this.covers = covers;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public boolean isFree() {
            return isFree;
        }

        public void setFree(boolean free) {
            isFree = free;
        }

        public long getDuration() {
            return duration;
        }

        public void setDuration(long duration) {
            this.duration = duration;
        }

        public long getSize() {
            return size;
        }

        public void setSize(long size) {
            this.size = size;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public int getQiniuStatus() {
            return qiniuStatus;
        }

        public void setQiniuStatus(int qiniuStatus) {
            this.qiniuStatus = qiniuStatus;
        }
    }

    public Long getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Long goodsId) {
        this.goodsId = goodsId;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getOperType() {
        return operType;
    }

    public void setOperType(String operType) {
        this.operType = operType;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public double getLng() {
        return lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public List<Long> getTagIds() {
        return tagIds;
    }

    public void setTagIds(List<Long> tagIds) {
        this.tagIds = tagIds;
    }

    public long getInterest() {
        return interest;
    }

    public void setInterest(long interest) {
        this.interest = interest;
    }

    public List<Guarantee> getGuarantees() {
        return guarantees;
    }

    public void setGuarantees(List<Guarantee> guarantees) {
        this.guarantees = guarantees;
    }

    public List<Video> getVideos() {
        return videos;
    }

    public void setVideos(List<Video> videos) {
        this.videos = videos;
    }

    public static final class Builder {
        private Long goodsId;
        private Integer version;
        private String operType;
        private int type;
        private String title;
        private String detail;
        private String cover;
        private String city;
        private int amount;
        private double lng;
        private double lat;
        private List<Long> tagIds;
        private long interest;
        private List<Guarantee> guarantees;
        private List<Video> videos;

        private Builder() {
            goodsId = null;
            version = null;
            operType = "";
            type = 0;
            title = "";
            detail = "";
            cover = "";
            city = "";
            amount = 0;
            lng = 0;
            lat = 0;
            tagIds = new LinkedList<>();
            interest = 0;
            guarantees = new LinkedList<>();
            videos = new LinkedList<>();
        }

        public Builder goodsId(Long goodsId) {
            this.goodsId = goodsId;
            return this;
        }

        public Builder version(Integer version) {
            this.version = version;
            return this;
        }

        public Builder operType(int publishOperationType) {
            switch (publishOperationType) {
                case PublishUtil.PUBLISH_OPERATION_TYPE_SAVE:
                    this.operType = "SAVE";
                    break;
                case PublishUtil.PUBLISH_OPERATION_TYPE_SUBMIT_REVIEW:
                    this.operType = "PUBLISH";
                    break;
            }
            return this;
        }

        public Builder type(int type) {
            this.type = type;
            return this;
        }

        public Builder title(String title) {
            this.title = title;
            return this;
        }

        public Builder detail(String detail) {
            this.detail = detail;
            return this;
        }

        public Builder cover(String cover) {
            this.cover = cover;
            return this;
        }

        public Builder city(String city) {
            this.city = city;
            return this;
        }

        public Builder amount(int amount) {
            this.amount = amount;
            return this;
        }

        public Builder lng(double lng) {
            this.lng = lng;
            return this;
        }

        public Builder lat(double lat) {
            this.lat = lat;
            return this;
        }

        public Builder tagIds(List<Long> tagIds) {
            this.tagIds = tagIds;
            return this;
        }

        public Builder interest(long interest) {
            this.interest = interest;
            return this;
        }

        public Builder guarantees(List<Guarantee> guarantees) {
            this.guarantees = guarantees;
            return this;
        }

        public Builder videos(List<Video> videos) {
            this.videos = videos;
            return this;
        }

        public Call<ResponseBody> build() {
            return ApiManager.getService().publishCourseVideo(new PublishCourseVideoRequest(this));
        }
    }
}
